package com.crl.ssc.dic.service;

import com.cars.util.global.GlobalOperaCode;
import com.cars.util.list.ListUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.crl.ssc.dic.dao.DicDistrictDao;
import com.crl.ssc.dic.dto.DicDistrictDTO;
import com.crl.ssc.dic.model.DicDistrict;
import com.crl.ssc.dic.vo.DicDistrictSearchVO;
import java.util.List;

/**
 * @description: 字典管理-区县字典Service
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020-07-26 14:44:13
 */
@Service
public class DicDistrictService {
    @Autowired
    private DicDistrictDao dicDistrictDao;
    /**
     * 增加
     *
     * @param dicDistrictDTO
     * @return
     */
    public int add(DicDistrictDTO dicDistrictDTO) {
        DicDistrict dicDistrict = new DicDistrict();
        BeanUtils.copyProperties(dicDistrictDTO, dicDistrict);
        return dicDistrictDao.add(dicDistrict);
    }
    /**
     * 修改
     *
     * @param dicDistrictDTO
     * @return
     */
    public int update(DicDistrictDTO dicDistrictDTO) {
        DicDistrict dicDistrict = new DicDistrict();
        BeanUtils.copyProperties(dicDistrictDTO, dicDistrict);
        return dicDistrictDao.update(dicDistrict);
    }
    /**
     * 删除
     *
     * @param districtCode
     * @return
     */
    public int delete(String districtCode) {
        DicDistrict dicDistrict = dicDistrictDao.get(districtCode);
        if (dicDistrict  == null) {
           return GlobalOperaCode.OPERA_NOT_EXIST;
         } else {
           return dicDistrictDao.delete(districtCode);
         }
    }

    /**
     * 列表
     *
     * @param dicDistrictSearchVO
     * @return
     */
    public List<DicDistrictDTO> list(DicDistrictSearchVO dicDistrictSearchVO) {
        List<DicDistrict> list = dicDistrictDao.list(dicDistrictSearchVO);
        List<DicDistrictDTO> listResult = ListUtils.copyList(list, DicDistrictDTO.class);
        return listResult;
    }
    /**
     * 记录条数
     *
     * @param dicDistrictSearchVO
     * @return
     */
    public int count(DicDistrictSearchVO dicDistrictSearchVO) {
        return dicDistrictDao.count(dicDistrictSearchVO);
    }
    /**
     * 获取单个
     *
     * @param districtCode
     * @return
     */
    public DicDistrictDTO get(String districtCode) {
        DicDistrict dicDistrict = dicDistrictDao.get(districtCode);
        DicDistrictDTO dicDistrictDTO = new DicDistrictDTO();
        BeanUtils.copyProperties(dicDistrict, dicDistrictDTO);
        return dicDistrictDTO;
    }
}
